﻿using System;
using System.Web.Mvc;

namespace Gonte.Web
{
    public static class FormCollectionExtensions
    {
        public static string ParseNodeId(this FormCollection collection, string key, out int nodeId)
        {
            string entityId = collection.GetValue(key).AttemptedValue;
            string[] parts = entityId.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

            // Verify we have all the required parts (2)

            // Verify that the second part is an integer convertible
            nodeId = int.Parse(parts[1].Trim());
            return parts[0].Trim();
        }
    }
}
